<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>增加记录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="layui-badge-dot"></span>用户名</label>
		<div class="layui-input-block">
			<input type="text" name="userName" autocomplete="off" class="layui-input" id="userName" lay-verify="required|username">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">管理员姓名</label>
		<div class="layui-input-block">
			<input type="text" name="userRealname" autocomplete="off" class="layui-input" id="userRealname" lay-verify="lenLimit20">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="layui-badge-dot"></span>登录密码</label>
		<div class="layui-input-block">
			<input type="password" name="userPwd"  id = "userPwd" lay-verify="required|userPwd" class="layui-input">	
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="layui-badge-dot"></span>确认密码</label>
		<div class="layui-input-block">
			<input type="password" lay-verify="required|userPwdCheck" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="layui-badge-dot"></span>手机号码</label>
		<div class="layui-input-block">
			<input type="text" name="title" autocomplete="off" class="layui-input" id="userTel" lay-verify="required|phone">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">备注</label> 
		<div  class="layui-input-block" >
			<input type="text" name="title" autocomplete="off" class="layui-input" id="userRemark" lay-verify="lenLimit50">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block" style="text-align: center;">
			<button type="button" class="layui-btn" lay-submit id="doSubmitAdd" lay-filter="doSubmitAdd"><i class="layui-icon">&#xe654;</i>新增</button>
			<button type="reset" class="layui-btn layui-btn-warm" ><i class="layui-icon">&#xe669;</i>重置</button>
		</div>
	</div>
	
</form>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script >
layui.use(['form','layer','laydate','table'],function(){
    var $ = layui.jquery;
    var form = layui.form;
    var table= layui.table;
    var layer = layui.layer;
    var laydate = layui.laydate;

 	//提交监听事件--新增记录
 	form.on("submit(doSubmitAdd)",function(){
	//$("#doSubmitAdd").click(function(index,layero){ //yw 使用这个方法不能进行form.verfy的验证
        $.ajax({
            type:"POST",
			url:"/user/addUser", 
			async:false, //yw 取消异步下载模式，否则shoolId2第一次打开没有数据，第二次打开才有数据
            data:{schoolid:$("#schoolId").val(),schoolname:$("#schoolId").find("option:selected").text(),userrealname:$("#userRealname").val(),username:$("#userName").val(),userpwd:$("#userPwd").val(),usertel:$("#userTel").val(),userremark:$("#userRemark").val()},
            success:function(res){  //yw res是后端的返回值,有的是int，有的是object;data是前端数据，data与res不能混淆
                //alert(res);
                if(res){
                    //刷新父页面
            		parent.location.reload();
                    layer.msg('新增成功',{icon:7,time:800,shade:[0.6,'#000',true]});                   
                }else{
                    layer.msg('新增失败',{icon:7,time:800,shade:[0.6,'#000',true]});
                }
                layer.closeAll('iframe'); //yw 关闭新增界面   type=2          
			},
			error:function(){
				return false;
			}
        });
	});
	
 	//表单验证
 	form.verify({
		required: [/[\S]+/, "不能为空"],
		username:[/^[a-zA-Z0-9_-]{4,16}$/,"用户名4-16位字母数字下划线减号"],
        phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
        email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
        url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
        integer: [/^\d*$/, "只能填写整数"],
        date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
        identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"],
        // 校验两次密码是否一致
        userPwd: [/(.+){6,12}$/, '密码必须6到12位'],
        userPwdCheck:function(value){
            if($('input[name=userPwd]').val() !== value)
                return '两次密码输入不一致！';
        },
        number: function (e) {
            if (e && isNaN(e))return "只能填写数字"
        },
        lenLimit20:function(value){
            if(value.length>20) return '长度不能超过20个字符';
        },
        lenLimit50:function(value){
            if(value.length>20) return '长度不能超过50个字符';
        }
    });

})
</script>
</body>
</html>